var express = require('express');
var path = require('path');
var fs = require('fs');
var router = express.Router();
// var UserService = require("../models/services/UserService")

/* GET home page. */
router.get('/', function(req, res) {
    res.render('index', { title: 'Express' });
});



router.get('/a', function(req, res) {
    var data =[];
    UserService.userPager({},1,5,(error,results)=>{

        // data = results;
        res.render('index', {list:results });
        // res.render(data)
    })

    // res.render(data);
});

/*var ext = path.extname(req.url);
console.log(ext)
if(ext == ".jpg"){
    console.log("jpg")
    //找到文件,把他读到stream
    res.writeHeader(200,{"Content-Type":"image/jpeg"})
    var filename = path.basename(req.url);
    var pathname = path.resolve(__dirname,"assets/images/"+filename);
    console.log(pathname)
    var readStream = fs.createReadStream(pathname);
    readStream.pipe(res);

    //pipe是自动调用 end()

}else{
    console.log("html")
    res.write(`
       <h1>this is server site...</h1>
       <img src="assets/images/server.jpg" />
    `);
    //写入完成后,关闭流
    res.end();
}*/


router.get('/administratorApi', function(req, res) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By",' 3.2.1');
    res.header("Content-Type","application/json");

    var AdministratorList =[
        {"title":"辣炒花蛤","dosing":"花蛤,姜,蒜,葱,红辣椒,青辣椒,豆芽,红糖,白酒","users":"独爱你",
            "pic":"../../static/images/pic1.png","pview":102.3,"collect":17489},
        {"title":"黑椒芦笋炒蘑菇","dosing":"花蛤,姜,蒜,葱,红辣椒,青辣椒,豆芽,红糖,白酒","users":"糯米baby",
            "pic":"../../static/images/pic2.png","pview":104.3,"collect":17489},
        {"title":"黄豆芽拌粉丝","dosing":"花蛤,姜,蒜,葱,红辣椒,青辣椒,豆芽,红糖,白酒","users":"醒墨轩",
            "pic":"../../static/images/pic1.png","pview":100.3,"collect":17789},
        {"title":"白灼金针菇","dosing":"花蛤,姜,蒜,葱,红辣椒,青辣椒,豆芽,红糖,白酒","users":"独爱你",
            "pic":"../../static/images/pic2.png","pview":107.3,"collect":14289},
        {"title":"土匪猪肝","dosing":"花蛤,姜,蒜,葱,红辣椒,青辣椒,豆芽,红糖,白酒","users":"萌奇奇他娘",
            "pic":"../../static/images/pic1.png","pview":10.3,"collect":17419},
        {"title":"冬笋炒腊肉","dosing":"花蛤,姜,蒜,葱,红辣椒,青辣椒,豆芽,红糖,白酒","users":"糯米baby",
            "pic":"../../static/images/pic2.png","pview":103.3,"collect":12489}
    ];
    res.json(AdministratorList);

});
router.get('/foodList', function(req, res) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By",' 3.2.1');
    res.header("Content-Type","application/json");

    var foodList =[
        {"title":"辣炒花蛤","dosing":"花蛤,姜,蒜,葱,红辣椒,青辣椒,豆芽,红糖,白酒","users":"独爱你",
            "pic":"../../static/images/pic3.png","pview":1010,"collect":26},
        {"title":"黑椒芦笋炒蘑菇","dosing":"花蛤,姜,蒜,葱,红辣椒,青辣椒,豆芽,红糖,白酒","users":"糯米baby",
            "pic":"../../static/images/pic4.png","pview":456,"collect":369},
        {"title":"黄豆芽拌粉丝","dosing":"花蛤,姜,蒜,葱,红辣椒,青辣椒,豆芽,红糖,白酒","users":"醒墨轩",
            "pic":"../../static/images/pic5.png","pview":300,"collect":450},
        {"title":"白灼金针菇","dosing":"花蛤,姜,蒜,葱,红辣椒,青辣椒,豆芽,红糖,白酒","users":"独爱你",
            "pic":"../../static/images/pic6.png","pview":142,"collect":140},
        {"title":"土匪猪肝","dosing":"花蛤,姜,蒜,葱,红辣椒,青辣椒,豆芽,红糖,白酒","users":"萌奇奇他娘",
            "pic":"../../static/images/pic7.png","pview":10,"collect":19},
        {"title":"冬笋炒腊肉","dosing":"花蛤,姜,蒜,葱,红辣椒,青辣椒,豆芽,红糖,白酒","users":"糯米baby",
            "pic":"../../static/images/pic8.png","pview":12.,"collect":129}
    ];
    res.json(foodList);

});
router.get('/headList', function(req, res) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By",' 3.2.1');
    res.header("Content-Type","application/json");

    var headList =[
        {"title":"每天吃一颗，不用搭支架，血管刷得特干净。","dosing":"花蛤,姜,蒜,葱,红辣椒,青辣椒,豆芽,红糖,白酒","users":"独爱你",
            "pic":"../../static/images/pic3.png","pview":1010,"collect":26},
        {"title":"过节别忘养生，这种主食别错过","dosing":"花蛤,姜,蒜,葱,红辣椒,青辣椒,豆芽,红糖,白酒","users":"糯米baby",
            "pic":"../../static/images/pic4.png","pview":456,"collect":369},
        {"title":"吃辣也能养胃,送给无辣不欢迎的你","dosing":"花蛤,姜,蒜,葱,红辣椒,青辣椒,豆芽,红糖,白酒","users":"醒墨轩",
            "pic":"../../static/images/pic5.png","pview":300,"collect":450},
        {"title":"炒菜时一定要改掉的4个坏习惯，为了家人健康看看吧！","dosing":"花蛤,姜,蒜,葱,红辣椒,青辣椒,豆芽,红糖,白酒","users":"独爱你",
            "pic":"../../static/images/pic6.png","pview":142,"collect":140},
        {"title":"别再番茄炒蛋了，炒这个更嫩滑！立刻多吃2碗饭","dosing":"花蛤,姜,蒜,葱,红辣椒,青辣椒,豆芽,红糖,白酒","users":"萌奇奇他娘",
            "pic":"../../static/images/pic7.png","pview":10,"collect":19},
        {"title":"鲑鱼喜欢吃小鱼，小鱼吃的是水藻，水藻中含有一种特殊的脂肪，称为“W-3脂肪酸”，能够预防血液中血小板凝集成块，","dosing":"花蛤,姜,蒜,葱,红辣椒,青辣椒,豆芽,红糖,白酒","users":"糯米baby",
            "pic":"../../static/images/pic8.png","pview":12.,"collect":129}
    ];
    res.json(headList);

});
module.exports = router;
